import tensorflow as tf
import logging
import os

class Tooler( object ):
    @staticmethod
    def restore_from_ckpt( ckpt_dir , sess , ):
        """
        only restore from newest graph and import the parameters
        if don't find any ckpt files: logging error

        the graph will be added to default graph
        if you wanna change the behavior, could input a graph parameter

        ckpt_dir: the directory holding the meta graph and ckpt
        sess : the process holding the parameters
        """
        ckpt_fullpath = tf.train.latest_checkpoint( ckpt_dir )
        if_ckpt_exist = tf.train.checkpoint_exists( ckpt_fullpath )

        if not if_ckpt_exist:
            logging.error( "the ckpt doesn't exist " )
    
        saver = tf.train.import_meta_graph( ckpt_fullpath + ".meta" )
        saver.restore( sess , ckpt_fullpath )

if __name__ == "__main__":
    sess = tf.Session()
    Tooler.restore_from_ckpt( "/Users/jh/working_data/tmp_OULU_p1c1_mobileNet_140_224_low_level1_noresize" , sess )

